package com.spirng.leetcode.day05;

import java.util.HashMap;
import java.util.HashSet;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test128  {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newSingleThreadExecutor();
//        executorService.execute();
        longestConsecutive(new int[]{0,3,7,2,5,8,4,6,0,1});
    }
    public static int longestConsecutive(int[] nums) {
        HashSet<Integer> set=new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            set.add(nums[i]);
        }
        int length=0;
        for (int num: set) {
            int cur=num;
            if(!set.contains(num-1)){
                int count=1;
                while (set.contains(cur+1)){
                    cur=cur+1;
                    count++;
             }
             length=count>length?count:length;
         }

        }
        return length;
    }
}
